package com.abocode.aichat.getway.modules;

import com.abocode.aichat.server.channel.ChannelWrapper;
import com.abocode.aichat.server.context.ServerRuntimeContext;
import com.abocode.aichat.server.modules.AbstractModule;
import com.abocode.aichat.server.modules.ModuleHandler;
import com.abocode.aichat.server.reply.Replies;
import com.abocode.aichat.server.stanza.Stanza;
import com.abocode.aichat.server.stanza.StanzaImpl;
import com.abocode.aichat.utils.HappBeanUtils;
import io.netty.channel.Channel;

import java.util.List;
import java.util.Map;

/**
 * Created by franky-21.
 */
public class GatewayModule extends AbstractModule {
    @Override
    public String version() {
        return "1.0";
    }
   private class GatewayAuthModuleHandler implements ModuleHandler {
        @Override
        public Replies execute(ChannelWrapper channelWrapper, Stanza stanza, ServerRuntimeContext serverRuntimeContext) {
            if ("reply".equals(stanza.module())) {
                Replies replies = new Replies();
                Map body = stanza.body();
                StanzaImpl newStanza = (StanzaImpl) HappBeanUtils.mapToObject(body,StanzaImpl.class);
                List<Channel> channel = serverRuntimeContext.getProtocolChannelRegistry().get(newStanza.findTo());
                replies.addReply(channel, newStanza);
                return replies;
            } else if ("auth".equals(stanza.module())) {

            }
            return null;
        }

        @Override
        public String module() {
            return null;
        }
    }

    @Override
    public String namespace() {
        return "gateway_auth";
    }
}
